package com.hds.modules.sys.service.base.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hds.common.utils.PageUtils;
import com.hds.common.utils.Query;
import com.hds.modules.app.entity.UserEntity;
import com.hds.modules.app.service.UserService;
import com.hds.modules.app.service.impl.UserServiceImpl;
import com.hds.modules.sys.dao.base.SysMemberShipDao;
import com.hds.modules.sys.entity.base.SysCompanyEntity;
import com.hds.modules.sys.entity.base.SysMemberShipEntity;
import com.hds.modules.sys.service.base.SysMemberShipService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;


/**
 * 会员
 *
 * @date 2018年06月18日 上午9:46:09
 */
@Service("sysMemberShipService")
public class SysMemberShipServiceImpl extends ServiceImpl<SysMemberShipDao, SysMemberShipEntity> implements SysMemberShipService {
	@Autowired
	private SysMemberShipDao sysMemberShipDao;
	@Autowired
	private UserService userService;

	@Override
	public Boolean save(SysMemberShipEntity memberShip) {
		memberShip.setCreateTime(new Date());
		Integer r = sysMemberShipDao.insert(memberShip);
		return r>0 ? true : false;
	}

	@Override
	public Boolean update(SysMemberShipEntity memberShip) {
		Integer r = sysMemberShipDao.updateById(memberShip);
		return r>0 ? true : false;
	}

	@Override
	public SysMemberShipEntity queryByLevel(Integer level) {
		return sysMemberShipDao.queryByLevel(level);
	}

	@Override
	public void deleteBatch(Long[] ids) {
		//sysMemberShipDao.deleteBatchIds(ids);
	}

	@Override
	public PageUtils queryPage(Map<String, Object> params) {
		String key = (String)params.get("key");

		Page<SysMemberShipEntity> page = this.selectPage(
				new Query<SysMemberShipEntity>(params).getPage(),
				new EntityWrapper<SysMemberShipEntity>().like(StringUtils.isNotBlank(key),"username", key)
		);

		return new PageUtils(page);
	}


}
